package com.TetrisII.views;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;

import javax.swing.JPanel;


import com.TetrisII.entities.Ground;
import com.TetrisII.entities.Shape;
import com.TetrisII.entities.ShapeFactory;
import com.TetrisII.global.Global;

/**
 * 游戏显示面板
 * 
 * @author Administrator
 *
 */
public class GamePanel extends JPanel {
	private Shape shape;
    private Ground ground;
	public GamePanel() {
		// TODO Auto-generated constructor stub    
		setFocusable(true);
		setBackground(Color.WHITE);
		setPreferredSize(new Dimension(Global.CELL * Global.WID, Global.CELL * Global.HGH));
		setVisible(true);
		;

	}

	/**
	 * 面板开始游戏
	 * @param shape
	 * @param ground
	 */
public void beginGame(Shape shape,Ground ground){
	this.shape=shape;
	this.ground=ground;
}
	/**
	 * 面板显示方块和底层数组
	 */
	public void paint(Graphics g) {
		super.paintComponent(g);
		Graphics2D g_2 = (Graphics2D) g;
		
		URL url=GamePanel.class.getResource("游戏面板背景.jpg");
		Image image=Toolkit.getDefaultToolkit().getImage(url);
		g_2.drawImage(image, 0, 0, Global.CELL * Global.WID, Global.CELL * Global.HGH,this);
		shape.paintShape(g_2,this);
		ground.paintGround(g_2,this);	
		repaint();

	}

	public Shape getShape() {
		return shape;
	}

	public void setShape(Shape shape) {
		this.shape = shape;
	}

	public Ground getGround() {
		return ground;
	}

	public void setGround(Ground ground) {
		this.ground = ground;
	}
}
